package cn.yuxiaoyuan.service.impl;

import cn.yuxiaoyuan.pojo.domain.DriverAuthMaterial;
import cn.yuxiaoyuan.mapper.DriverAuthMaterialMapper;
import cn.yuxiaoyuan.result.JSONResult;
import cn.yuxiaoyuan.service.IDriverAuthMaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 司机实名资料 服务实现类
 * </p>
 *
 * @author whale
 * @since 2025-06-12
 */
@Service
public class DriverAuthMaterialServiceImpl extends ServiceImpl<DriverAuthMaterialMapper, DriverAuthMaterial> implements IDriverAuthMaterialService {

    @Override
    public JSONResult driverAuth(DriverAuthMaterial driverAuthMaterial) {

        DriverAuthMaterial byId = super.getById(driverAuthMaterial.getId());
        if(byId != null && byId.getRealAuthStatus() == 0){
           return JSONResult.error("请勿重复提交");
        }
        if(byId != null && byId.getRealAuthStatus() == 1){
            return JSONResult.error("审核已经通过");
        }
        if(byId != null && byId.getRealAuthStatus() == 2){
            driverAuthMaterial.setRealAuthStatus(0);
            driverAuthMaterial.setDriverId(driverAuthMaterial.getId());
            driverAuthMaterial.setUpdateTime(new Date());
            super.updateById(driverAuthMaterial);
            return JSONResult.success(driverAuthMaterial.getRealAuthStatus());
        }
        driverAuthMaterial.setRealAuthStatus(0);
        driverAuthMaterial.setDriverId(driverAuthMaterial.getId());
        driverAuthMaterial.setCreateTime(new Date());
        super.save(driverAuthMaterial);
        return JSONResult.success(driverAuthMaterial.getRealAuthStatus());
    }
}
